<template>
  <div>
    <div v-for="history in historyList" :key="history.id">
      <SingleHistory :history="history" :is-question="true"></SingleHistory>
    </div>
    <div v-if="historyList.length === 0" class="noData">
      当前没有提出问题！！
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { HistoryService } from "@/services/history.service";
import SingleHistory from "@/components/SingleHistory.vue";

@Component({
  name: "MyQuestion",
  components: { SingleHistory }
})
export default class MyQuestion extends Vue {
  historyList = [];

  mounted() {
    this.getHistoryList();
  }

  getHistoryList() {
    HistoryService.getMyQuestion().then((res: any) => {
      this.historyList = res.histories.map((item: any) => {
        item.answer = item.answer.replace(/\\n/g, "<br>");
        return item;
      });
      this.historyList = this.historyList.reverse();
    }).catch((err: any) => {
      throw new Error(err);
    });
  }



}
</script>

<style scoped lang="scss">
.noData {
  margin: 200px;
  font-size: 28px;
}
</style>
